package com.test.springboot.jpa.pojo;

import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * @author thinkpad - 83start
 * @version v1.0
 * @create 2022/8/18 2:45
 * @package com.test.springboot.jpa.pojo
 * @description 文件说明
 */

@Entity
@Data
@Table(name = "tb_user")
@EntityListeners(AuditingEntityListener.class)
public class User implements Serializable {
    /**
     * 用户id : 主键，bigint，最大长度为 5，自增
     */
    @Id
    @Column(name = "user_id",length = 5)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long userId;

    /**
     * 用户名：varchar(20),不为空,唯一值属性
     */
    @Column(name = "user_name",length = 20,nullable = false,unique = true)
    public String userName;

    /**
     * 用户密码：varchar(20),不为空
     */
    @Column(name = "user_password",length = 20,nullable = false)
    public String userPassword;

    /**
     * 创建时间：create 时候生效
     */
    @CreatedDate
    @Column(name = "create_time")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date createTime;

    /**
     * 更新时间：update 时候生效
     */
    @LastModifiedDate
    @Column(name = "update_time")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date updateTime;

    public User() {
    }

    public User(Long userId) {
        this.userId = userId;
    }

    public User(String userName, String userPassword) {
        this.userName = userName;
        this.userPassword = userPassword;
    }

    public User(Long userId, String userName, String userPassword) {
        this.userId = userId;
        this.userName = userName;
        this.userPassword = userPassword;
    }
}
